#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

void solve()
{
    int ans = -1;
    int n;
    cin >> n;
    string s;
    cin >> s;
    string ss[1010];
    for (int i = 1; i <= n;i++)
    {
        cin >> ss[i];
        if(ss[i]==s)
        {
            ans = i;
        }
    }
    cout << ans << endl;
}
int main()
{
   int t = 1;
    cin >> t;
    while(t--)
    {
        solve();
    }
   return 0;
}
